﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.CBO.SCM.Item;
    using UFSoft.UBF.AopFrame;
    using UFSoft.UBF.Business;
    using UFSoft.UBF.Util.Context;

	/// <summary>
	/// ItemBatchUpdateSV partial 
	/// </summary>	
	public partial class ItemBatchUpdateSV 
	{	
		internal BaseStrategy Select()
		{
			return new ItemBatchUpdateSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class ItemBatchUpdateSVImpementStrategy : BaseStrategy
	{
		public ItemBatchUpdateSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			ItemBatchUpdateSV bpObj = (ItemBatchUpdateSV)obj;

            try
            {
                String path = "1=1";
                if(!String.IsNullOrEmpty(bpObj.Data?.MainItemCategory?.Code))
                    path += $" and MainItemCategory.Code={bpObj.Data.MainItemCategory.Code}";
                if (!String.IsNullOrEmpty(bpObj.Data?.ItemCode))
                    path += $" and Code like '%{bpObj.Data.ItemCode}%'";
                ItemMaster.EntityList itemList = ItemMaster.Finder.FindAll(path);
				using(ISession session = Session.Open())
				{
                    foreach (var item in itemList)
                    {
						//料品状态改为修改,触发update事件插件
						session.Modify(item);
                    }
					session.Commit();
                }

                return ResultUtils.success(bpObj, bpObj.Data, null);
            }
            catch (Exception ex)
            {
                return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
        }		
	}

	#endregion
	
	
}